<?php
declare (strict_types=1);

namespace app\admin\controller\school;

use think\facade\Request;
use app\common\service\SchoolTeamTask as S;
use app\common\model\SchoolTeamTask as M;

class TeamTask extends \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        return $this->getAuto($this->fetch(), M::getList());
    }

    // 添加
    public function add()
    {
        $month = date('m');
        $time = [];
        for ($i = $month;$i<=12;$i++){
            $time[] = date('Y-').$i;
        }
        return $this->getAuto($this->fetch('add',['month'=>$time]), S::goAdd(Request::post()));
    }

    // 编辑
    public function edit($id)
    {
        $month = date('m');
        $time = [];
        for ($i = $month;$i<=12;$i++){
            $time[] = date('Y-').$i;
        }
        $admin = session('admin');
//        $model =  M::where('admin_id', $admin['id']) ->where('month', toDate(time(), 'Y-m'))->find();
        return $this->getAuto($this->fetch('', ['model' => M::find($id),'month'=>$time, 'admin_id' => $admin['id']]), S::goEdit(Request::post(), $id));
    }

    // 状态
    public function status($id)
    {
        return $this->getJson(S::goStatus(Request::post('status'), $id));
    }

    // 删除
    public function remove($id)
    {
        return $this->getJson(S::goRemove($id));
    }

    // 批量删除
    public function batchRemove()
    {
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
    }

    // 回收站
    public function recycle()
    {
        return $this->getAuto($this->fetch(), S::goRecycle());
    }

}
